<?php
session_start();


include("functions.php");

$max_vote = 3;

$slang = $_GET["slang"];
//$slang = str_replace("'","&#039",$slang);

$key_pref = $_GET["key_pref"];
$vote_flow = $_GET["vote_flow"];


//$dir = $_SERVER['PHP_SELF'];
$host  = $_SERVER['HTTP_HOST'];
//$uri  = rtrim($_SERVER['PHP_SELF'], '/\\'); //in live, set this to ""
$uri = "";
//$uri = "/gproj";

/*$id= $_GET["id"];
if(isset($_SESSION[$id."good"]))  $_SESSION[$id."good"]=$_SESSION[$id."good"]+1;
	else  $_SESSION[$id."good"]=0;
*/



if($vote_flow==0)
{
	//echo "you're not voting";
	//do nothing
}
else if($vote_flow==1)
{
	

	//echo "you're voting up";
	$id= $_GET["id"];
	
	
	if(isset($_SESSION[$id."up"]))  $_SESSION[$id."up"]=$_SESSION[$id."up"]+1;
	else  $_SESSION[$id."up"]=1;
	
	//echo "vote up=". $_SESSION[$id."up"]; 
	
	
   if($_SESSION[$id."up"]<= $max_vote)
   {
	increase_voteup($id);
	
	$slang1 = htmlspecialchars($slang,ENT_QUOTES);
	//echo "'http://$host$uri/search.php?slang=$slang1&key_pref=$key_pref&vote_flow=0'";
	//PRG pattern baby....
	echo "<META HTTP-EQUIV=\"Refresh\" Content=\"0; URL='http://$host$uri/search.php?slang=$slang1&key_pref=$key_pref&vote_flow=0'\">"; 
   }
   else
   {
   	//echo "that's too much voting, man";

	//header("Location: http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=0");
	 echo "<META HTTP-EQUIV=\"Refresh\" Content=\"0; URL='http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=3'\">"; 
   }

}
else if($vote_flow==2)
{
	//echo "you're voting down";
//	$id= $_GET["id"];
//	increase_votedown($id);
//	header("Location: http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=0");


$id= $_GET["id"];
	
	
	if(isset($_SESSION[$id."down"]))  $_SESSION[$id."down"]=$_SESSION[$id."down"]+1;
	else  $_SESSION[$id."down"]=1;
	
	//echo "vote up=". $_SESSION[$id."up"]; 
	
	
   if($_SESSION[$id."down"]<= $max_vote)
   {
	increase_votedown($id);
	//PRG pattern baby....
	echo "<META HTTP-EQUIV=\"Refresh\" Content=\"0; URL='http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=0'\">"; 
   }
   else
   {
   	//echo "that's too much voting, man";

	//header("Location: http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=0");
	 echo "<META HTTP-EQUIV=\"Refresh\" Content=\"0; URL='http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=3'\">"; 
   }
}
else if($vote_flow == 3)
{
	//print_message("Hey hey hey...that's a lot of voting","red");
	//print_message("Hey hey hey...that's a lot of voting","red");
}
else if($vote_flow == 4)
{
	//next and previous
	$id= $_GET["id"];
	//get everying with id
	
	$id_result = select_by_id($id);
	$id_row = mysql_fetch_array($id_result);
	if($id_row['slangBurmese']==NULL)
	{
		$slang = $id_row['slangBurglish'] ;
		$key_pref = "bglish";
	}
	else
	{
		$slang = $id_row['slangBurmese'];
		$key_pref = "bur";
	}
	
}

?>









<HTML>
<HEAD>
    <TITLE>Word Rebel</TITLE>


<link rel="stylesheet" type="text/css" href="default.css">
<script language="JavaScript" src="javascript_functions.js"></script>



<BODY bgcolor="999966" onload="document.search.textbox.focus()">


<?
//if($vote_flow==1 && $_SESSION[$id."up"]<3)
//{
//  echo "<script language=\"javascript\">
//	<!-- 
//
//	location.replace(\"http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=0\");
//
//	-->
//	</script>";
//}

?>


<TABLE BORDER="0" CELLPADDING=0 CELLSPACING=0 width="683" align="center">


<TR><TD valign="top" colspan="3"><img src="images/title-gawdi.gif" border=0 width="683" height="71"></TD></TR>



<TR><TD valign="top" colspan="3">

<P><BR>
<!-- MENU -->


<? print_main_menu(); ?>

</TD></TR>






<TR><TD valign="top" style="word-wrap:break-word;">



<!-- LEFT COL -->



<?

//messages
if($vote_flow == 3)
{
	print_message("Hey hey hey...that's a lot of voting","red");
}

if($slang == "")
{
	print_message("please do not search for blank","red");
}


else if($key_pref=="bglish")
{
	$a = isPresent_gaw($slang, $key_pref);
	if($a == true)
	{
		//if the word is in the table, print it out
		$result = select_from_burglish($slang);
		while($row = mysql_fetch_array($result))
		{
			print_result_holder_top();

            if($row['slangBurmese']== NULL)
            {
            	$key_pref = "bglish";
            	
            	print_div_tag($row['id']);
				print_result($row['slangBurglish'],$row['definitionBurglish'],$row['exampleBurglish'],$row['voteup'],$row['votedown'],$row['author'],$row['id'],$key_pref);
				print_close_div_tag();
				
				if($row['completed']==0)
				{
					//print hidden form
					print_hidden_form($row['id']);
				}
				else if($row['completed']==1)
				{
					if(isset($_SESSION[$row['id']."goodbad"]))  
					{
						//echo "it is set"; no noeed to add 1 since search page is not doing teh good bad voting
						//$_SESSION[$id."goodbad"]=$_SESSION[$id."goodbad"]+1;
					}
					else  
					{
							//echo "setting 1";
						$_SESSION[$row['id']."goodbad"]=0;
					}
					
					if($_SESSION[$row['id']."goodbad"] <1)
					{
	
							//print hidden vote form with good bad button
							print_hidden_unapproved_burmese($row['id']);
					}
					else
					{
						print_hidden_unapproved_burmese_no_button($row['id']);
						//echo "you already voted..i'm not gonna print the hidden bos";
					}
					
					
					
				}
				
            }
            else
            {
            	//echo "there's burmese entries, so print in burmese";
            	//let's change the key_pref to bur, and slang to the burmse slang and search again
            	$key_pref = "bur";
            	//$slang = $row['slangBurmese'];
            	print_result($row['slangBurmese'],$row['definitionBurmese'],$row['exampleBurmese'],$row['voteup'],$row['votedown'],$row['authorBurmese'],$row['id'],$key_pref);
            	
            	if($row['completed']==2)
				{
					//burmese entry is approved. show the orig
					print_hidden_original($row['id']);
					
					//echo "hey";
				}
            
            	//echo "<META HTTP-EQUIV=\"Refresh\" Content=\"0; URL='http://$host$uri/search.php?slang=$slang&key_pref=$key_pref&vote_flow=0'\">"; 
            
            }

			print_result_holder_bottom();
		}
	}
	else
	{
		//if there was no exact match...
		print_result_holder_top();
		echo "<p class=text>sorry <b>$slang</b> can't be found</p>";
		$result_array = array();
		$result_array = cheap_guess($slang, $key_pref,$result_array);

		if(count($result_array)==0 && strlen($slang) > 5)
		{
			//echo "cheap guess1 can't find anything, let's chop off the word and cheap_guess again<br>";
			$pieces = strlen($slang)/3 ; //why 3?? 3 might be the minimum average number of chars in burmese to make sense; not really sure tho
			$chopped = chopper($slang,$pieces);
			for($i=0; $i < count($chopped);$i++)
			{
				//echo "i'm searcing for <p class=textdarkb> $chopped[$i]</p>";
				$result_array = cheap_guess($chopped[$i],$key_pref,$result_array);
				//echo count($result_array);
			}
		}

		print_cheap_guess($result_array,$key_pref);
		print_result_holder_bottom();
	}
}
else if($key_pref=="bur")
{
	//echo "im lokkin for $slang";
	$slang = burmese_special_char_decoder($slang);
$a = isPresent_gaw($slang, $key_pref);

//echo "$a";

	if($a == true)
	{
		//echo "i'm in true";
		//if the word is in the table, print it out
		$result = select_from_burmese($slang);
		while($row = mysql_fetch_array($result))
		{
			print_result_holder_top();

		 	if($row['slangBurmese']== NULL)
            {
            	
            	$key_pref = "bglish";
				print_result($row['slangBurglish'],$row['definitionBurglish'],$row['exampleBurglish'],$row['voteup'],$row['votedown'],$row['author'],$row['id'],$key_pref);
            }
            
            else
            {
				
				//echo " i'm goin into print_result";
				print_result($row['slangBurmese'],$row['definitionBurmese'],$row['exampleBurmese'],$row['voteup'],$row['votedown'],$row['authorBurmese'],$row['id'],$key_pref);

           		 if($row['completed']==2)
				{
					//burmese entry is approved. show the orig
					print_hidden_original($row['id']);
					
					//echo "hey";
				}
            }

			print_result_holder_bottom();
			
		
		}
	}
	else
	{
		print_result_holder_top();
		echo "<p class=textb>aqm&D;yJ/ <b>$slang</b> ukd&SmvkdYrawGUbl;/</p>";
		$result_array = array();
		$result_array = cheap_guess($slang, $key_pref,$result_array);

		if(count($result_array)==0 && strlen($slang) > 5)
		{
			//echo "cheap guess1 can't find anything, let's chop off the word and cheap_guess again<br>";
			$pieces = strlen($slang)/3 ; //why 3?? 3 might be the minimum average number of chars in burmese to make sense; not really sure tho
			$chopped = chopper($slang,$pieces);
			for($i=0; $i < count($chopped);$i++)
			{
				//echo "i'm searcing for <b class=textdarkb> $chopped[$i]</b> $chopped[$i] <br>";
				$result_array = cheap_guess($chopped[$i],$key_pref,$result_array);
				//echo count($result_array);
			}
		}

		print_cheap_guess($result_array,$key_pref);
		print_result_holder_bottom();

	}
}


print_random_amount(5);



?>






<!-- END LEFT COL -->






</td>

<td><img src="images/space.gif" border=0 width="11" height="1"></td>





<TD valign=top>





<!-- START RIGHT COLUMN TOP -->





<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 width="208">

<TR>
<TD colspan="3"><img src="images/x_top.gif" border=0 width="208" height="175"></TD></TR>

<TR>
<TD background="images/star_left.gif" width="17"><img src="images/space.gif" border=0 width="17" height="1"></TD>

<TD bgcolor="CC3300" align=center>
<img src="images/space.gif" border=0 width="176" height="1"><BR>


<? print_search_box($key_pref); ?>




</TD>

<TD background="images/star_right.gif" width="17"><img src="images/space.gif" border=0 width="17" height="1"></TD>

</TR>


<TR>
<TD colspan="3"><img src="images/star_bott.gif" border=0 width="208" height="22"></TD></TR>


</TABLE>


<!-- END RIGHT COLUMN TOP -->











</td></tr>






<tr><td colspan="3" align=center>


<P><BR><!-- Copyright -->

<p class="textlight">gollystarz &copy; 2006</p>
<P><BR>



</td></tr>




</table>








<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1322223-1";
urchinTracker();
</script>
</BODY>
</HTML>
